//! system接口的controller
use axum::{
    middleware,
    routing::{get, post, put},
    Router,
};

use crate::middleware::operator_middleware;
pub mod dept;
pub mod dict;
pub mod log;
pub mod resource;
pub mod role;
pub mod user;

pub fn get_route<S>() -> Router<S>
where
    S: Sync + Send + Clone + 'static,
{
    #[cfg_attr(rustfmt,rustfmt_skip)]
    Router::new()
        // 用户管理
        .route("/user/", get(user::list).post(user::create))
        .route("/user/update_password", post(user::update_password))
        .route("/user/:id", get(user::fetch_one).put(user::update).delete(user::delete))
        // 部门管理
        .route("/dept/", get(dept::tree_table).post(dept::create))
        .route("/dept/:id", get(dept::fetch_one).put(dept::update).delete(dept::delete))
        // 资源管理
        .route("/resource/", get(resource::fetch_list).post(resource::create))
        .route("/resource/all", get(resource::fetch_all))
        .route("/resource/:id", put(resource::update).delete(resource::delete))
        // 角色管理
        .route("/role/", get(role::list).post(role::create))
        .route("/role/all", get(role::all))
        .route("/role/resource/:id", get(role::fetch_role_resource).put(role::update_role_resource))
        .route("/role/:id", put(role::update).delete(role::delete))
        // 字典管理
        .route("/dict/type/", get(dict::list_dict).post(dict::create))
        .route("/dict/type/:id", put(dict::update).delete(dict::delete))
        .route("/dict/data/:dict_type/", get(dict::list_dict_data).post(dict::create_dict_data))
        .route("/dict/data/:dict_type/:id",put(dict::update_dict_data).delete(dict::delete_dict_data))
        // 日志记录
        .route("/log/login", get(log::login_log_list).delete(log::login_log_delete))
        .route("/log/operate", get(log::operate_log_list).delete(log::operate_log_delete))
        .route_layer(middleware::from_fn(operator_middleware))
}
